package edu.gmu.projects.fireresponder;

import java.io.FileNotFoundException;
import java.io.PrintStream;

public class RelevanceEngineTester {
	/*
	 * public double calculateRelevanceValue(Asset asset) { double probOfFire =
	 * asset.getProbabilityOfFire(); // currently not implemented // double
	 * probOfPeople = asset.getProbabilityOfPresence();
	 * 
	 * double coveredByFire = fusionEngine.getPercentageOnFire(0.25, asset);
	 * double proximityToFire = fusionEngine.getFireDistance(asset, 0.25);
	 * Double proximityToResponder = proximityToAsset(currentLocation, asset);
	 * 
	 * double proxyToFireNorm = proximityToFire > 1 ? 0 : 1 - proximityToFire;
	 * double proxyToResponderNorm = (proximityToResponder == null ||
	 * proximityToResponder > 1) ? 0 : 1 - proximityToResponder;
	 * 
	 * // double probOfFireAndPeopleTerm = probOfFire * probOfPeople; double
	 * probOfFireAndPeopleTerm = probOfFire; double proxyToFireAndCoverageTerm =
	 * 0.65 * proxyToFireNorm + 0.35 coveredByFire;
	 * 
	 * return 0.4 * probOfFireAndPeopleTerm + 0.3 * proxyToFireAndCoverageTerm +
	 * 0.3 * proxyToResponderNorm; }
	 */

	public static enum RelevanceScale {
		NOT_RELEVANT, SLIGHT_RELEVANCE, LOW_RELEVANCE, MODERATE_RELEVANCE, HIGH_RELEVANCE, VERY_HIGH_RELEVANCE
	};

	public static RelevanceScale getRelevanceScale(double relevance) {
		if (0 < relevance && relevance < 0.2) {
			return RelevanceScale.SLIGHT_RELEVANCE;
		} else if (0.2 <= relevance && relevance < 0.4) {
			return RelevanceScale.LOW_RELEVANCE;
		} else if (0.4 <= relevance && relevance < 0.6) {
			return RelevanceScale.MODERATE_RELEVANCE;
		} else if (0.6 <= relevance && relevance < 0.8) {
			return RelevanceScale.HIGH_RELEVANCE;
		} else if (0.8 <= relevance && relevance <= 1) {
			return RelevanceScale.VERY_HIGH_RELEVANCE;
		}

		return RelevanceScale.NOT_RELEVANT;
	}

	public static String getRelevanceScaleText(RelevanceScale scale) {
		switch (scale) {
		case NOT_RELEVANT:
			return "NONE";
		case SLIGHT_RELEVANCE:
			return "SLIGHT";
		case LOW_RELEVANCE:
			return "LOW";
		case MODERATE_RELEVANCE:
			return "MODERATE";
		case HIGH_RELEVANCE:
			return "HIGH";
		case VERY_HIGH_RELEVANCE:
			return "VERY HIGH";
		}

		return "UNKNOWN";
	}

	public static String getRelevanceScaleText(double value) {
		return getRelevanceScaleText(getRelevanceScale(value));
	}

	/*
	 * public static void main(String[] args) {
	 * 
	 * final double INTERVAL = 0.25;
	 * 
	 * try { PrintStream stream = new PrintStream("relevance.txt");
	 * 
	 * //String title =
	 * String.format("%-10s %-10s %-10s %-10s %-20s %-20s %-20s %-24s %-20s",
	 * "Fire", "People", "Covered", "Prox Fire", "Prox to FR",
	 * "FirePeople Term", "FireProxyCoverageTerm", "ProxyToFRTerm", "Relevance",
	 * "Relevance Text"); //stream.println(title);
	 * 
	 * for (double probOfFire = 0; probOfFire <= 1; probOfFire += INTERVAL) {
	 * for (double probOfPeople = 0; probOfPeople <= 1; probOfPeople +=
	 * INTERVAL) { for (double precentCovered = 0; precentCovered <= 1;
	 * precentCovered += INTERVAL) { for (double proximityToFire = 1;
	 * proximityToFire >= 0; proximityToFire -= INTERVAL) { for (double
	 * proximityToResponder = 1; proximityToResponder >= 0; proximityToResponder
	 * -= INTERVAL) { double probOfFireAndPeopleTerm = probOfFire *
	 * probOfPeople; double proximityToFireNorm = 1 - proximityToFire; double
	 * proximityToResponderNorm = 1 - proximityToResponder; double
	 * proxyToFireAndCoverageTerm = 0.65 * proximityToFireNorm + 0.35 *
	 * precentCovered; double relevance = 0.4 * probOfFireAndPeopleTerm + 0.3 *
	 * proxyToFireAndCoverageTerm + 0.3 * proximityToResponderNorm;
	 * 
	 * String relevanceString = String.format("%f %f %f %f %f %f %f %f %f %s",
	 * probOfFire, probOfPeople, precentCovered, proximityToFire,
	 * proximityToResponder, probOfFireAndPeopleTerm,
	 * proxyToFireAndCoverageTerm, proximityToResponderNorm, relevance,
	 * getRelevanceScaleText(relevance)); stream.println(relevanceString); } } }
	 * } } } catch (FileNotFoundException e) { e.printStackTrace(); }
	 * 
	 * System.out.println("Done"); }
	 */

	public static void main(String[] args) {
		PrintStream stream;
		try {
			stream = new PrintStream("relevance.txt");

			for (double probOfFire = 0; probOfFire <= 1; probOfFire += 0.1) {
				
				for (double probOfPeople = 0; probOfPeople <= 1; probOfPeople += 0.1) {

					for (int estimatedTimeTo = 0; estimatedTimeTo <= 3600; estimatedTimeTo += 600) {
					
						for (double probOfFireThen = 0; probOfFireThen <= 1; probOfFireThen += 0.1) {

							double relevance = calculateRelevanceValue(probOfFire,
									probOfPeople, estimatedTimeTo,
									probOfFireThen);

							String relevanceString = String.format(
									"%.6f %.6f %d %.6f %.6f", probOfFire, probOfPeople,
									estimatedTimeTo, probOfFireThen, relevance);
							
							System.out.println(relevanceString);

							stream.println(relevanceString);

						}
					}
				}
			}

			stream.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static double calculateRelevanceValue(double probOfFire,
			double probOfPeople, int estimatedTimeTo, double probOfFireThen) {

		double estimatedTimeToNorm = estimatedTimeTo > 3600 ? 0
				: estimatedTimeTo / 3600.0;
		double scaledTimeTerm = 1.0 - Math.pow(estimatedTimeToNorm, 2);

		return 0.5 * (probOfPeople * probOfFire) + 0.2 * scaledTimeTerm + 0.3
				* probOfFireThen;
	}
}
